<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>uCXpresso.BLE: CMutex Class Reference</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../upnp.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">uCXpresso.BLE
   &#160;<span id="projectnumber">v1.0.4</span>
   </div>
   <div id="projectbrief">RTOS C++ Framework for Bluetooth Low Energy</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.6 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="../../index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="../../modules.html"><span>Modules</span></a></li>
      <li class="current"><a href="../../annotated.html"><span>Classes</span></a></li>
      <li><a href="../../examples.html"><span>Examples</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="../../search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="../../search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="../../annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="../../classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="../../hierarchy.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="../../functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('d3/d0d/class_c_mutex.html','../../');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Groups</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="../../d9/db1/class_c_mutex-members.html">List of all members</a>  </div>
  <div class="headertitle">
<div class="title">CMutex Class Reference<div class="ingroups"><a class="el" href="../../d8/dba/group___r_t_o_s.html">RTOS</a></div></div>  </div>
</div><!--header-->
<div class="contents">

<p><code>#include &quot;<a class="el" href="../../d0/df8/mutex_8h_source.html">class/mutex.h</a>&quot;</code></p>
<div class="dynheader">
Inheritance diagram for CMutex:</div>
<div class="dyncontent">
 <div class="center">
  <img src="../../d3/d0d/class_c_mutex.png" usemap="#CMutex_map" alt=""/>
  <map id="CMutex_map" name="CMutex_map">
<area href="../../dc/dac/class_c_object.html" alt="CObject" shape="rect" coords="0,0,58,24"/>
</map>
 </div></div>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a820d77775dfd7d5dddfdac6bbf89b67a"><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d3/d0d/class_c_mutex.html#a820d77775dfd7d5dddfdac6bbf89b67a">lock</a> ()</td></tr>
<tr class="separator:a820d77775dfd7d5dddfdac6bbf89b67a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:adb89cb4258a492458db9fb614c1681a9"><td class="memItemLeft" align="right" valign="top">virtual bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d3/d0d/class_c_mutex.html#adb89cb4258a492458db9fb614c1681a9">tryLock</a> (uint32_t delay=0)</td></tr>
<tr class="separator:adb89cb4258a492458db9fb614c1681a9"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aee0e6661ae4b790104a9a4205910d53d"><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d3/d0d/class_c_mutex.html#aee0e6661ae4b790104a9a4205910d53d">unlock</a> ()</td></tr>
<tr class="separator:aee0e6661ae4b790104a9a4205910d53d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a26a76c241a4d62d2efdac57d2cfe4c0f"><td class="memItemLeft" align="right" valign="top">virtual bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/dac/class_c_object.html#a26a76c241a4d62d2efdac57d2cfe4c0f">isThread</a> ()</td></tr>
<tr class="separator:a26a76c241a4d62d2efdac57d2cfe4c0f"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Use the <a class="el" href="../../d3/d0d/class_c_mutex.html">CMutex</a> class to lock or unlock a resource. </p>
<dl class="section note"><dt>Note</dt><dd>Mutexes and binary semaphores are very similar but have some subtle differences: Mutexes include a priority inheritance mechanism, binary semaphores do not. This makes binary semaphores the better choice for implementing synchronisation (between tasks or between tasks and an interrupt), and mutexes the better choice for implementing simple mutual exclusion. </dd></dl>
</div><h2 class="groupheader">Member Function Documentation</h2>
<a class="anchor" id="a26a76c241a4d62d2efdac57d2cfe4c0f"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">virtual bool CObject::isThread </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">virtual</span><span class="mlabel">inherited</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Check current object that inherits from <a class="el" href="../../d0/d26/class_c_thread.html">CThread</a> class or not. </p>
<dl class="section note"><dt>Note</dt><dd>The isTherad() will be override by <a class="el" href="../../d0/d26/class_c_thread.html">CThread</a> class. </dd></dl>

<p>Reimplemented in <a class="el" href="../../d0/d26/class_c_thread.html#ab2513fd0fcad30e2e6605609c91f1984">CThread</a>.</p>

</div>
</div>
<a class="anchor" id="a820d77775dfd7d5dddfdac6bbf89b67a"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">virtual void CMutex::lock </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Call the member function to lock (take semaphore) a resource with block when resource in used.</p>
<div class="fragment"><div class="line">Example:</div>
<div class="line">        <a class="code" href="../../d3/d0d/class_c_mutex.html">CMutex</a> mutex;</div>
<div class="line"></div>
<div class="line">        <a class="code" href="../../d8/d1d/class_c_serial.html">CSerial</a> cdc(USB);</div>
<div class="line">        <a class="code" href="../../d6/d56/class_console.html">Console</a> (cdc);</div>
<div class="line"></div>
<div class="line">        <span class="keyword">class </span>Task1: <span class="keyword">public</span> <a class="code" href="../../d0/d26/class_c_thread.html">CThread</a> {</div>
<div class="line">        <span class="keyword">protected</span>:</div>
<div class="line">            <span class="keyword">virtual</span> <span class="keywordtype">void</span> run() {</div>
<div class="line">            <span class="keywordflow">while</span>(1) {</div>
<div class="line">                <span class="keywordflow">if</span> ( cdc.isConnected() ) {</div>
<div class="line">                    mutex.<a class="code" href="../../d3/d0d/class_c_mutex.html#a820d77775dfd7d5dddfdac6bbf89b67a">lock</a>();</div>
<div class="line">                    con &lt;&lt; <span class="stringliteral">&quot;1111111111&quot;</span> &lt;&lt; endl;</div>
<div class="line">                    mutex.<a class="code" href="../../d3/d0d/class_c_mutex.html#aee0e6661ae4b790104a9a4205910d53d">unlock</a>();</div>
<div class="line">                }</div>
<div class="line">            }</div>
<div class="line">            }</div>
<div class="line">        };</div>
<div class="line"></div>
<div class="line">        <span class="keyword">class </span>Task2: <span class="keyword">public</span> <a class="code" href="../../d0/d26/class_c_thread.html">CThread</a> {</div>
<div class="line">        <span class="keyword">protected</span>:</div>
<div class="line">            <span class="keyword">virtual</span> <span class="keywordtype">void</span> run() {</div>
<div class="line">            <span class="keywordflow">while</span>(1) {</div>
<div class="line">                <span class="keywordflow">if</span> ( cdc.isConnected() ) {</div>
<div class="line">                    mutex.<a class="code" href="../../d3/d0d/class_c_mutex.html#a820d77775dfd7d5dddfdac6bbf89b67a">lock</a>();</div>
<div class="line">                    con &lt;&lt; <span class="stringliteral">&quot;2222222222&quot;</span> &lt;&lt; endl;</div>
<div class="line">                    mutex.<a class="code" href="../../d3/d0d/class_c_mutex.html#aee0e6661ae4b790104a9a4205910d53d">unlock</a>();</div>
<div class="line">                }</div>
<div class="line">            }</div>
<div class="line">            }</div>
<div class="line">        };</div>
</div><!-- fragment --> 
</div>
</div>
<a class="anchor" id="adb89cb4258a492458db9fb614c1681a9"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">virtual bool CMutex::tryLock </td>
          <td>(</td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>delay</em> = <code>0</code></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Call the member function to lock (take) a resource without block when resource in used. </p>
<dl class="section return"><dt>Returns</dt><dd>true if lock successful; otherwise, failed. </dd></dl>

</div>
</div>
<a class="anchor" id="aee0e6661ae4b790104a9a4205910d53d"></a>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">virtual void CMutex::unlock </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Call the member function to unlock (release) a resource.</p>
<div class="fragment"><div class="line">Example:</div>
<div class="line">        <a class="code" href="../../d3/d0d/class_c_mutex.html">CMutex</a> mutex;</div>
<div class="line"></div>
<div class="line">        <a class="code" href="../../d8/d1d/class_c_serial.html">CSerial</a> cdc(USB);</div>
<div class="line">        <a class="code" href="../../d6/d56/class_console.html">Console</a> (cdc);</div>
<div class="line"></div>
<div class="line">        <span class="keyword">class </span>Task1: <span class="keyword">public</span> <a class="code" href="../../d0/d26/class_c_thread.html">CThread</a> {</div>
<div class="line">        <span class="keyword">protected</span>:</div>
<div class="line">            <span class="keyword">virtual</span> <span class="keywordtype">void</span> run() {</div>
<div class="line">            <span class="keywordflow">while</span>(1) {</div>
<div class="line">                <span class="keywordflow">if</span> ( cdc.isConnected() ) {</div>
<div class="line">                    mutex.<a class="code" href="../../d3/d0d/class_c_mutex.html#a820d77775dfd7d5dddfdac6bbf89b67a">lock</a>();</div>
<div class="line">                    con &lt;&lt; <span class="stringliteral">&quot;1111111111&quot;</span> &lt;&lt; endl;</div>
<div class="line">                    mutex.<a class="code" href="../../d3/d0d/class_c_mutex.html#aee0e6661ae4b790104a9a4205910d53d">unlock</a>();</div>
<div class="line">                }</div>
<div class="line">            }</div>
<div class="line">            }</div>
<div class="line">        };</div>
<div class="line"></div>
<div class="line">        <span class="keyword">class </span>Task2: <span class="keyword">public</span> <a class="code" href="../../d0/d26/class_c_thread.html">CThread</a> {</div>
<div class="line">        <span class="keyword">protected</span>:</div>
<div class="line">            <span class="keyword">virtual</span> <span class="keywordtype">void</span> run() {</div>
<div class="line">            <span class="keywordflow">while</span>(1) {</div>
<div class="line">                <span class="keywordflow">if</span> ( cdc.isConnected() ) {</div>
<div class="line">                    mutex.<a class="code" href="../../d3/d0d/class_c_mutex.html#a820d77775dfd7d5dddfdac6bbf89b67a">lock</a>();</div>
<div class="line">                    con &lt;&lt; <span class="stringliteral">&quot;2222222222&quot;</span> &lt;&lt; endl;</div>
<div class="line">                    mutex.<a class="code" href="../../d3/d0d/class_c_mutex.html#aee0e6661ae4b790104a9a4205910d53d">unlock</a>();</div>
<div class="line">                }</div>
<div class="line">            }</div>
<div class="line">            }</div>
<div class="line">        };</div>
</div><!-- fragment --> 
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="../../d3/d0d/class_c_mutex.html">CMutex</a></li>
    <li class="footer">Generated on Fri Apr 11 2014 23:43:26 for uCXpresso.BLE by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="../../doxygen.png" alt="doxygen"/></a> 1.8.6 </li>
  </ul>
</div>
</body>
</html>
